package com.weipai.demo.controller;

import com.weipai.demo.enums.RetCode;
import com.weipai.demo.model.ApplyforLoans;
import com.weipai.demo.service.ApplyforLoansService;
import com.weipai.demo.util.LayuiTablePagingResult;
import com.weipai.demo.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Author: 赵项阳
 * @Date: 2019/6/28 17:38
 * @Version 1.0
 */
@RestController
public class ApplyforLoansController {


    @Autowired
    private ApplyforLoansService applyforLoansService;

    //页面用户申请贷款
    @RequestMapping(value = "/loans/applyFor")
    public Response applyFor(ApplyforLoans applyforLoans, HttpServletRequest request){
        Response response = new Response();
        HttpSession session = request.getSession();
        String code = request.getParameter("code");
        String sessionQrcode = (String) session.getAttribute("code" + code);
        if(sessionQrcode == null){
            response.setCode(RetCode.ERRORCODE);
            return response;
        }
        String code1 = request.getParameter("qrcode").toLowerCase();
        if (sessionQrcode.toLowerCase().equals(code1)) {
            return applyforLoansService.applyFor(applyforLoans);
        } else {
            response.setCode(RetCode.ERRORCODE);
            return response;
        }
    }

    //展示贷款信息
    @RequestMapping(value = "/loans/showApplyfor")
    public LayuiTablePagingResult showApplyfor(Integer page,Integer size){
       return applyforLoansService.showApplyFor(page,size);
    }

    //申请用户是否通过审核
    @RequestMapping(value = "/loans/audit")
    public Response audit(Integer id,Integer status){
        return applyforLoansService.audit(id,status);
    }

    //申请贷款用户删除
    @RequestMapping(value = "/loans/delete")
    public Response delete(Integer id){
        return applyforLoansService.delete(id);
    }

    //==================================================================================================================

    //图片随机点击
    @RequestMapping(value = "/loans/dynamic")
    public void dynamic(HttpServletRequest request, HttpServletResponse response){
        applyforLoansService.dynamic(request,response);
    }


    //添加贷款分类
    @RequestMapping(value = "/loans/save")
    public Response save(String loansClassName,String introduce,String status){
      return applyforLoansService.save(loansClassName,introduce,status);
    }

    //检测是否已支付
    @RequestMapping(value = "/loans/checkPay")
    public Response checkPay(String phone){
      return applyforLoansService.checkPay(phone);
    }

    //==================================================================================================================




}
